package com.fafu.dao;

import com.fafu.domian.user.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface UserDao {
	/**
	 * 用户注册
	 * 1.判断用户名重复(用户登录)
	 * 2.用户保存
	 * 3.用户激活
	 */
	/*
	findByUsername用处：
	1.查看用户是否注册
	2.用户登录
	3.查看激活状态
	 */
	@Select("select * from user where username = #{username}")
	public User findByUsername(String username);
	//2.用户保存
	@Insert("insert into user(username,password,name,status,code,createdate) values(#{username},#{password},#{name},#{status},#{code},#{createdate})")
	public void save(User user);
	//3.用户激活
	//3.1用唯一标识码查找用户
	@Select("select * from user where code = #{code}")
	public User findByCode(String code);
	//3.2改变用户状态
	@Update("update user set status = 'Y' where id = #{id}")
	public void updateStatus(User user);
	/**
	 * 查找所有用户
	 */
	@Select("select * from user")
	public List <User> findAll();
	/**
	 * 根据ID 更新密码
	 */
	@Update("update user set password = #{password} where id = #{id}")
	public void updatePassword(User user);
	/**
	 *  更新激活码
	 *  自动封装失败，采用@Param注解封装
	 */
	@Update("update user set code = #{code} where username = #{username}")
	public void updateCode(@Param("username")String username, @Param("code")String code);



}
